var myApp = new Framework7();
var meetings;
$(function () {
    var params=JSON.stringify({"userId":$.cookie("user")});
    $.ajax({
        // url:'http://125.65.40.171/conference-check/conferenceController/selectAllConferences',
        url:'conferenceController/selectAllConferences',
        dataType:'json',
        data:{"param":params},
        type:"post",
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success:function (data) {
            if(data.code==200){
                meetings=data.data.dataList;
                $.each(data.data.dataList,function (e,v) {
                    $("#meetingName").append("<option value='"+v.id+"'>"+v.name+"</option>");
                    if(e==0){
                        $(".item-after").text(v.name);
                        $("#meetingDate").val(v.date);
                        $("#meetingPlace").val(v.site);
                        $("#meetingCost").val(v.cost);
                        // $(".QR_code").attr("src","http://125.65.40.171/conference-check/imageController/showIamgeFromServer?type="+v.imageType+"&identifyId="+v.imageIdentifyId);
                        $(".QR_code").attr("src","imageController/showIamgeFromServer?type="+v.imageType+"&identifyId="+v.imageIdentifyId);
                    }
                });
                $("#meetingName").on("change",function(e,v){
                    var index=$(this).find("option:checked").val();
                    $.each(meetings,function (e,v) {
                        if(v.id==index){
                            $("#meetingDate").val(v.date);
                            $("#meetingPlace").val(v.site);
                            $("#meetingCost").val(v.cost);
                            // $(".QR_code").attr("src","http://125.65.40.171/conference-check/imageController/showIamgeFromServer?type="+v.imageType+"&identifyId="+v.imageIdentifyId);
                            $(".QR_code").attr("src","imageController/showIamgeFromServer?type="+v.imageType+"&identifyId="+v.imageIdentifyId);
                        }
                    });
                });
            }else if(data.code==500){
                $(".submit").attr("disabled","disabled");
                myApp.alert('','没有可申请会议');
            }
        },
        error:function (XMLHttpRequest,textStatus,errorThrown) {
            myApp.alert('','系统错误，请稍后重试');
        }
    });
    $(".submit").on("click",function () {
        var count=$("#count").val();
        var money=$("#money").val();
        var flg=0;
        if(count==""){
            var flg=0;
            myApp.alert('','请输入打款账户');
        }else{
            if(money==""){
                var flg=0;
                myApp.alert('','请输入打款金额');
            }else{
                var params=JSON.stringify({"conventionerId":$.cookie("user"),"conferenceId":$("#meetingName").val(),"payAccount":count,"amountOfPay":money});
                $.ajax({
                    // url:'http://125.65.40.171/conference-check/conferenceController/applyConference',
                    url:'conferenceController/applyConference',
                    dataType:'json',
                    xhrFields: {
                        withCredentials: true
                    },
                    crossDomain: true,
                    data:{"param":params},
                    type:"post",
                    success:function (data) {
                        if(data.code==200){
                            window.location.href="checking";
                        }else if(data.code==500){
                            myApp.alert('','申请失败');
                        }
                    },
                    error:function (XMLHttpRequest,textStatus,errorThrown) {
                        myApp.alert('','系统错误，请稍后重试');
                    }
                })
            }
        }
    });
});